<template>
  <div class="musicList">
    <div class="musicListTop">
      <div class="title">发现好歌单</div>
      <div class="more">查看更多></div>
    </div>
    <van-swipe class="my-swipe" :autoplay="false" :indicator-color="white" :show-indicators="false">
      <van-swipe-item v-for="(item) in playlists" :key="item">
        <div class="mlist">
          <div class="mbox" v-for="(item) in item" :key="item.id">
            <router-link :to="{ path: '/listviews', query: { id: item.id } }">
              <img :src="item.picUrl" alt />
              <div class="text">
                <span>{{ item.name }}</span>
              </div>
            </router-link>
          </div>
        </div>
      </van-swipe-item>
    </van-swipe>
  </div>

  <!-- <div class="mbox" ></div>
      <div class="mbox"></div>
  <div class="mbox"></div>-->
</template>
<script>
import { getplayLists } from '../js/axios'

export default {
  data () {
    return {
      playlists: []
    }
  },
  created () {
    this.getplaylists()
  },
  methods: {
    async getplaylists () {
      var that = this
      getplayLists().then((res) => {
        // console.log(res.data.result)
        for (var i = 0; i < res.data.result.length; i += 3) {
          that.playlists.push(res.data.result.slice(i, i + 3))
        }
        // console.log(that.playlists)
        // that.playlists = res.data.playlists
      })
    }
  },
}
</script>

<style lang="less" scoped>
.musicList {
  .musicListTop {
    display: flex;
    justify-content: space-between;
    margin-top: 0.3rem;
    .title {
      font-weight: 700;
    }
  }
  .mlist {
    display: flex;
    .mbox {
      margin-top: 0.2rem !important;
      flex: 1;
      // height: 2rem;
      // background: red;
      img {
        width: 100%;
        height: auto;
        border-radius: 0.1rem;
      }
      .text {
        span {
          overflow: hidden;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          word-break: break-all;
          font-size: 0.24rem;
        }
      }
    }
    .mbox:nth-child(n) {
      margin: 0 0.1rem;
    }
    .mbox:nth-last-child(1) {
      margin: 0;
    }
    .mbox:nth-child(1) {
      margin: 0;
    }
  }
}
</style>

